package sis.studentinfo;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.AbstractMap.SimpleEntry;
import java.util.Scanner;
import java.util.logging.Level;
import java.util.logging.LogManager;
import java.util.logging.Logger;

public class ValidateUtil {

    final static Logger logger = Logger.getLogger(ValidateUtil.class.getName());
    private static String NullMsg;
    private static String EmptyStringMsg;

    // override default logging properties for entire project sis
    static{
       try {
            InputStream is = new FileInputStream("sis.properties");
            LogManager.getLogManager().readConfiguration(is);
        } catch (IOException ex) {
            Logger.getLogger(ValidateUtil.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SecurityException ex) {
            Logger.getLogger(ValidateUtil.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    public static void checkNullEmpty(SimpleEntry<String, Object>... arguments) {
        for (SimpleEntry<String, Object> o : arguments) {
            if (o == null || o.getValue() == null) {
                if (o != null) {
                    NullMsg = "Argument " + o.getKey() + " cannot be null.";
                } else {
                    NullMsg = "SimpleEntry argument cannot be null.";
                }
                logger.info(NullMsg);
                throw new IllegalArgumentException(NullMsg);
            }

            if (o.getValue() instanceof String && ((String) o.getValue()).isEmpty()) {
                EmptyStringMsg = "Argument " + o.getKey() + " cannot be empty.";
                logger.info(EmptyStringMsg);
                throw new IllegalArgumentException(EmptyStringMsg);
            }

        }
    }
    public static void checkNull(SimpleEntry<String, Object>... arguments) {
        for (SimpleEntry<String, Object> o : arguments) {
            if (o == null || o.getValue() == null) {
                if (o != null) {
                    NullMsg = "Argument " + o.getKey() + " cannot be null.";
                } else {
                    NullMsg = "SimpleEntry argument cannot be null.";
                }
                logger.info(NullMsg);
                throw new IllegalArgumentException(NullMsg);
            }
        }
    }
    static String getNullMsg()
    {
        return NullMsg;
    }
    static String getEmptyStringMsg()
    {
        return EmptyStringMsg;
    }
}